<template>
  <div class="flexbox">
    <div class="dropdownitem">
      <el-dropdown @command="handleCommand1" trigger="click">
        <el-button type="primary">
          小王<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            v-for="item in list"
            :key="item.id"
            class="item flexbox"
            :command="item.id"
          >
            {{ item.msg }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <div v-if="this.$store.state.answer[18][0] > -1">
        <img :src="list[this.$store.state.answer[18][0]].url" alt="" />{{
          list[this.$store.state.answer[18][0]].msg
        }}
      </div>
    </div>
    <div class="dropdownitem">
      <el-dropdown @command="handleCommand2" trigger="click">
        <el-button type="primary">
          小明<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            v-for="item in list"
            :key="item.id"
            class="item flexbox"
            :command="item.id"
          >
            {{ item.msg }}</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
      <div v-if="this.$store.state.answer[18][1] > -1">
        <img :src="list[this.$store.state.answer[18][1]].url" alt="" />{{
          list[this.$store.state.answer[18][1]].msg
        }}
      </div>
    </div>
    <div class="dropdownitem">
      <el-dropdown @command="handleCommand3" trigger="click">
        <el-button type="primary">
          小张<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            v-for="item in list"
            :key="item.id"
            class="item flexbox"
            :command="item.id"
          >
            {{ item.msg }}</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
      <div v-if="this.$store.state.answer[18][2] > -1">
        <img :src="list[this.$store.state.answer[18][2]].url" alt="" />{{
          list[this.$store.state.answer[18][2]].msg
        }}
      </div>
    </div>
    <div class="dropdownitem">
      <el-dropdown @command="handleCommand4" trigger="click">
        <el-button type="primary">
          小李<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            v-for="item in list"
            :key="item.id"
            class="item flexbox"
            :command="item.id"
          >
            {{ item.msg }}</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
      <div v-if="this.$store.state.answer[18][3] > -1">
        <img :src="list[this.$store.state.answer[18][3]].url" alt="" />{{
          list[this.$store.state.answer[18][3]].msg
        }}
      </div>
    </div>

    <div class="dropdownitem">
      <el-dropdown @command="handleCommand5" trigger="click">
        <el-button type="primary">
          小华<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            v-for="item in list"
            :key="item.id"
            class="item flexbox"
            :command="item.id"
          >
            {{ item.msg }}</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
      <div v-if="this.$store.state.answer[18][4] > -1">
        <img :src="list[this.$store.state.answer[18][4]].url" alt="" />{{
          list[this.$store.state.answer[18][4]].msg
        }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Drag2",
  data() {
    return {
      list: [
        {
          id: 0,
          msg: "第1",
        },
        {
          id: 1,
          msg: "第2",
        },
        {
          id: 2,
          msg: "第3",
        },
        {
          id: 3,
          msg: "第4",
        },
        {
          id: 4,
          // url: require("../assets/img/捕5.png"),
          msg: "第5",
        },
      ],
    };
  },
  methods: {
    updata() {
      console.log(this.$store.state.pagenum, this.$store.state.answer);
      parent.postMessage(this.$store.state, "*");
    },
    handleCommand1(command) {
      this.$store.state.answer[18][0] = command;
      this.$forceUpdate();
      this.updata();
    },
    handleCommand2(command) {
      this.$store.state.answer[18][1] = command;
      this.$forceUpdate();
      this.updata();
    },
    handleCommand3(command) {
      this.$store.state.answer[18][2] = command;
      this.$forceUpdate();
      this.updata();
    },
    handleCommand4(command) {
      this.$store.state.answer[18][3] = command;
      this.$forceUpdate();
    },
    handleCommand5(command) {
      this.$store.state.answer[18][4] = command;
      this.$forceUpdate();
      this.updata();
    },
  },
};
</script>
<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}

.dropdownitem {
  width: 100px;
  height: 120px;
}
.el-dropdown .el-button {
  font-size: 20px;
  padding: 10px;
}
.el-dropdown-menu {
  width: 100px;
}
.el-dropdown-menu li {
  font-size: 20px;
}
</style>
